package com.drinkdelivery.front.controller;

import com.drinkdelivery.common.core.domain.AjaxResult;
import com.drinkdelivery.common.result.CommonResult;
import com.drinkdelivery.front.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author lzhCreate
 * @create 2024-07-17 10:34
 */
@Slf4j
@RestController
@RequestMapping("front/auth")
@Api(tags = "用户 -- 登录注册")
public class AuthController {

    @Autowired
    private AuthService loginService;

    @ApiOperation(value = "微信登录小程序授权登录")
    @PostMapping(value = "/login")
    public CommonResult<Map<String, Object>> wechatRoutineLogin(
            @RequestParam @ApiParam(value = "由小程序前端传来的临时登录凭证code") String code) {
        return CommonResult.success(loginService.wechatRoutineLogin(code));
    }

    /**
     * 用户登出
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "微信登录小程序授权登录")
    @GetMapping(value = "/logout")
    public AjaxResult wechatRoutineLogout(HttpServletRequest request) {
        return AjaxResult.success(loginService.wechatRoutineLogout(request));
    }

}
